package com.xjj.service.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.lang.reflect.Method;

/**
 * @Description 简单定时任务处理
 * @Author zhangjin
 * @Date 2022/10/21 9:44
 */
public class SchedulerJob implements Job {
    /**
     * 通过反射，指定时间执行Myjob的test方法
     * @param context
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        // todo 远程调用微服务，value保存服务名以及方法
        String value = context.getMergedJobDataMap().getString("value");

        try{
            String className = value.substring(0,value.lastIndexOf("."));
            Class<?> aClass = Class.forName(className);
            // 获得方法
            String method = value.substring(value.lastIndexOf(".")+1);
            Method method1 = aClass.getMethod(method);
            // 执行方法
            method1.invoke(aClass.newInstance());
        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }
    }
}
